<template>
  <div class="LoginBox">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span class="card-span">登录</span>
          <el-button class="button" @click="register" text>注册</el-button>
        </div>
      </template>
      <el-form status-icon label-width="100px" class="demo-ruleForm">
        <el-form-item label="账号" prop="pass">
          <el-input type="password" autocomplete="off" v-model="account" />
        </el-form-item>

        <el-form-item label="密码" prop="checkPass">
          <el-input type="password" autocomplete="off" v-model="password" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">登录</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="changePassword">修改密码</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { usersLoginAPI } from "@/API/User.ts"
import { ElNotification } from 'element-plus'
import { ref } from "vue";
import { useRouter } from "vue-router";

let $router = useRouter()

let account = ref<string>("")
let password = ref<string>("")
const submitForm = () => {
  usersLoginAPI({
    account: account.value,
    password: password.value
  }).then(res => {
    if (res.status == 200) {
      ElNotification({
        message: res.data.msg,
        type: 'success',
      })
      sessionStorage.setItem("token", res.data.data.token)
      sessionStorage.setItem("userid", res.data.data.id)
    }
    $router.push("/")
  })

}

//注册
let register = () => {
  $router.push("/addusers")
}

//修改密码
let changePassword = () => {
  $router.push("changePass")
}



</script>

<style scoped>
.LoginBox {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #cce8cf;
}

.button,
.card-span {
  width: 50%;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-card__body {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.el-button {
  width: 100%;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.box-card {
  width: 480px;
}

.button {
  width: 100px;
}
</style>
